package Arrays;

import java.util.Scanner;

/**
 * 作者:hfj
 * 功能:移除字符串中的尾随零
 * 日期: 2024/6/29 9:57
 */
public class RemoveTrailingZeros {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入一个数字:");
        String s = scanner.nextLine();
        System.out.println("结果为:" + removeTrailingZeros(s));
    }

    public static String removeTrailingZeros(String num) {
        int i = num.length() - 1;
        while (i >= 0 && num.charAt(i) == '0'){
            i--;
        }
        return num.substring(0,i+1);
    }
}
